package com.chuantou.yuba.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chuantou.yuba.R;
import com.chuantou.yuba.api.to.BDPoiTO;
import com.chuantou.yuba.util.ViewHolder;

public class LocationAdapter extends BaseAdapter {
	private Context mContext;
	private List<BDPoiTO> mPois = new ArrayList<BDPoiTO>();

	public LocationAdapter(Context context) {
		this.mContext = context;
	}

	public void add(List<BDPoiTO> pois) {
		if (pois != null && !pois.isEmpty()) {
			mPois.addAll(pois);
		}
	}

	public void addFirst(BDPoiTO poi) {
		mPois.add(0, poi);
	}

	public void clear() {
		mPois.clear();
	}

	@Override
	public int getCount() {
		return mPois.size();
	}

	@Override
	public Object getItem(int position) {
		return mPois.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = View.inflate(mContext, R.layout.location_item, null);
		}
		BDPoiTO to = mPois.get(position);
		TextView nameView = ViewHolder.get(convertView, R.id.name);
		nameView.setText(to.getName());
		TextView addressView = ViewHolder.get(convertView, R.id.address);
		addressView.setText(to.getAddress());
		return convertView;
	}

}